package logic

import (
	"context"
	"novel/model/mysql"

	"novel/novelrpc/internal/svc"
	"novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookshelfAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookshelfAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookshelfAddLogic {
	return &BookshelfAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookshelfAddLogic) BookshelfAdd(in *novelrpc.BookshelfAddRequest) (*novelrpc.BookshelfAddResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.Bookshelf

	if user.ID == 0 {
		user = mysql.Bookshelf{
			UserId:  int(in.UserId),
			NovelId: int(in.NovelId),
		}
		mysql.DB.Debug().Create(&user)
	}
	mysql.DB.Debug().Create(&user)

	return &novelrpc.BookshelfAddResponse{
		BookshelfId: int64(user.ID),
	}, nil
}
